package org.example.test3;

import java.io.*;

public class main {
    //3.使用缓冲流完成文件的复制(文件路径和内容自定义)
    public static void main(String[] args) {
        String sourceFilePath = "src/source.txt";
        String targetFilePath = "target.txt";

        try (BufferedReader reader = new BufferedReader(new FileReader(sourceFilePath));
             BufferedWriter writer = new BufferedWriter(new FileWriter(targetFilePath))) {

            String line;

            while ((line = reader.readLine()) != null) {
                writer.write(line);
                writer.newLine(); // 换行
            }

            System.out.println("文件复制完成。");

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
